home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_10_08
/
1008052a
< prev
next >
Wrap
Text File
|
1992-05-13
|
3KB
|
103 lines
/* Listing 5 */
/*****************************************************
Name: EXAMPLE.C
Description: Example program for ray / surface
intercepts
Portability: Standard C, MSC with GRAPHICS_ON
*****************************************************/
#include <stdio.h>
#define GRAPHICS_ON
#if defined( GRAPHICS_ON )
#include <graph.h>
#endif
#include <matrix_t.h>
#include <srf_trns.h>
#include <srf_incp.h>
void main( void )
{
double T[3], Ip[3], DirH[3], DirV[3],
IpH[MAX_NUM_INCP], IpV[MAX_NUM_INCP],
Offset, MinH = 0.0, MaxH = 10.0, MinV = 0.0,
MaxV = 10.0, LocH[3], LocV[3], LocHAxis,
LocVAxis, StpHAxis, StpVAxis;
matrix_t C;
size_t i, NmSteps = 100;
int NmIpH = 0, NmIpV = 0, IpNm;
/* Create a matrix and fill with coefficients
** for a sphere with radius 5. */
C = cr_matrix( 4, 4 );
C[1][1] = C[2][2] = C[3][3] = 0.2; C[0][3] = 2;
/* Translate the sphere to x = 5, y = 5, z = 5 */
T[0] = T[1] = T[2] = -5.0;
srf_trans( C, T );
#if defined( GRAPHICS_ON )
/* put screen in graphics mode. */
_setvideomode( _MRESNOCOLOR );
#endif
/* Loop through some contours */
StpHAxis = ( MaxH - MinH ) / NmSteps;
StpVAxis = ( MaxV - MinV ) / NmSteps;
for ( Offset = 0.0; Offset < 5.0; Offset += 2.0 )
{
/* Loop through all the pixels. */
for ( i = 1, LocHAxis = MinH + StpHAxis,
LocVAxis = MinV + StpVAxis;
( i <= NmSteps ) &&
( LocHAxis <= MaxH ) &&
( LocVAxis <= MaxV );
i++, LocHAxis += StpHAxis,
LocVAxis += StpVAxis )
{
/* Start a ray in the horizontal
** direction going to the right.
** Start a ray in the Vical
** direction goting up. X is horizontal,
** Y is the Vical, Z is normal. */
DirH[0] = DirV[1] = 1.0;
DirH[1] = DirH[2] = 0.0;
DirV[0] = DirV[2] = 0.0;
LocH[0] = MinH;
LocH[1] = LocVAxis;
LocV[0] = LocHAxis;
LocV[1] = MinV;
LocH[2] = LocV[2] = Offset;
NmIpH = srf_intrcpt( 2, LocH, DirH, C, IpH );
NmIpV = srf_intrcpt( 2, LocV, DirV, C, IpV );
for ( IpNm = 0; IpNm < NmIpH; IpNm++ )
{
Ip[0] = LocH[0] + IpH[IpNm];
Ip[1] = LocH[1];
#if defined( GRAPHICS_ON )
_setpixel( (short)( Ip[0] / MaxH *
320.0 ), (short)( Ip[1] /
MaxV * 200.0 ) );
#else
printf( "%g,\t%g,\t%g\n", Ip[0], Ip[1],
Offset );
#endif
}
for ( IpNm = 0; IpNm < NmIpV; IpNm++ )
{
Ip[0] = LocV[0];
Ip[1] = LocV[1] + IpV[IpNm];
#if defined( GRAPHICS_ON )
_setpixel( (short)( Ip[0] / MaxH *
320.0 ), (short)( Ip[1] /
MaxV * 200.0 ) );
#else
printf( "%g,\t%g,\t%g\n", Ip[0], Ip[1],
Offset );
#endif
}
} /* for i */
} /* for Offset */
fr_matrix( C, 4 );
} /* function main */
/* End of File */